<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar" id="tbToolBar">
                <div class="layui-form-item">
					<div class="layui-inline">
						<button id="btnAddBizProperty" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>创建场景</button>
					</div>
                    <div class="layui-inline" style="float: right;margin-right: 0px;">
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<label class="layui-form-label w-auto">场景</label>
							<div class="layui-input-inline mr0">
								<input name="name" class="layui-input" type="text" placeholder="请输入场景名称"/>
							</div>
						</div>
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<button class="layui-btn icon-btn" lay-filter="formSubSearchBizProperty" lay-submit>
								<i class="layui-icon">&#xe615;</i>查询
							</button>
						</div>					
					</div>
				</div>
				<table class="layui-table" id="tableBizProperty" lay-filter="tableBizProperty"></table>
			</div>
		</div>
	</div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarBizProperty">
	<a class="layui-btn layui-btn-xs" lay-event="view">查看</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="tableStateBizProperty">
#[[  {{#  if(d.status === '1'){ }}
    <span style="color: #23aa2e;">正常</span>
  {{#  } else { }}
	<span style="color: #ff0000;">禁止</span>
  {{#  } }}
]]#
</script>



<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var config = layui.config;

        form.render('select');
        // 渲染表格
        var insTb = table.render({
            elem: '#tableBizProperty',
            url: '#(ctx)/biz/property/listData', 
            page: true,
            toolbar: false,
            cellMinWidth: 100,
            where:{
            	objId:'#(objId)'
            },
            cols: [[
                {type: 'numbers', title: '序号'},
                {field: 'key', sort: false, title: '标识'},
                {field: 'value', sort: false, title: '值'},
                {align: 'left', toolbar: '#tableBarBizProperty', title: '操作', fixed: 'right',width: 170}
            ]],
        });

        // 添加
		$('#btnAddBizProperty').click(function () {
	        layer.load(2);
	        var formData={}; 
	        formData['BizProperty.title']='未命名';
              	admin.req("biz/scene/save",formData, function (res) {
                  layer.closeAll('loading');
                  if (res.code == 200) {
                      layer.msg(res.message, {icon: 1});
                      insTb.reload({}, 'data');
                  } else {
                      layer.msg(res.message, {icon: 2});
                  }
            }, 'get');
			 
		});
        // 搜索
        form.on('submit(formSubSearchBizProperty)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(tableBizProperty)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
            	 window.open('#(ctx)/biz/property/editor?id='+data.id,"_blank");
            } else if (layEvent === 'del') { 
                doDel(data.id, data.title);
            } else if (layEvent === 'view') { 
            	window.open('#(ctx)/biz/theme?sceneId='+data.id,"_blank");
            }
        });

        // 删除
        function doDel(id, name) {
            layer.confirm('确定要删除“' + name + '”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/scene/delete', {
                    id: id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({}, 'data');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'get');
            });
        }



    });
</script>
